* do file: make_dta.do
* originally created by Dawn Koffman for Janet Currie on May 4, 2020
* creates Stata dta files from 2005-2013 US Natality txt files

capture log close
log using make_dta.txt, text replace
set varabbrev off
foreach y in 2005 2006 2007 2008 2009 2010 2011 2012 2013 {
clear
#delimit ;
infix
str  version        7
int  dob_yy         15-18
int  dob_mm         19-20
int  dob_wk         29
str  ostate         30-31
int  mager          89-90
int  mbstate_rec    100
int  mracerec       143
int  mracehisp      149
int  mar            153
int  meducA         155
int  umeduc         156-157
int  meducS         158
int  dobf_mm        165-166
int  dobf_dd        167-168
int  dobf_imp       169
int  dobf_yy        170-173
int  dobf_byp       174
int  fagerpt_flg    175
int  fagerpt        176-177
int  fagecomp       178-179
int  ufagecomp      180-181
into fagecomb       182-183
int  ufagecomb      184-185
int  fagerec11      186-187
int  fbrace         188-189
int  fraceimp       190
int  fracerec       191
int  fhisp          192-194
int  ufhisp         195
int  fracehisp      196
int  feducA         197
int  feduc_byp      198
int  ufrace         199-200
int  fmultirace     201-202
int  lbo_rec        212
int  tbo_rec        217
int  dplural        423
using "NATL`y'\NATL`y'US.AllCnty.txt"
;
#delimit cr
compress
label variable version     "Version - A=2003 (revised) version, S=1989 (standard) version"
label variable dob_yy      "Birth Year"
label variable dob_mm      "Birth Month"
label variable dob_wk      "Weekday - 1=Sunday ... 7=Saturday"
label variable ostate      "Occurence Postal State"
label variable mager       "Mother's Age Recode 41"
label variable mbstate_rec "Mother's Birth State Recode - 1=Native Born, 2=Foreign Born"
label variable mracerec    "Mother's Race Recode"
label variable mracehisp   "Mother's Race/Hispanic Origin"
label variable mar         "Mother's Marital Status"
label variable meducA      "Mother's Educ - Revised"
label variable umeduc      "Mother's Educ - Unrevised"
label variable meducS      "Mother's Education Recoded"
label variable ufagecomb   "Father's Combined Age (Unrevised)"
label variable fracerec    "Father's Race Recode"
label variable fracehisp   "Father's Race/Hisp Origin"
label variable feducA      "Father's Education"
label variable lbo_rec     "Live Birth Order Recode"
label variable tbo_rec     "Total Birth Order Recode"
label variable dplural     "Plurality Recode - 1=Single ... 5=Quintuplet or higher"

label define dob_wk 1 Sun 2 Mon 3 Tue 4 Wed 5 Thu 6 Fri 7 Sat
label define mager 12 "10-12 years" 50 "50 years and over"
label define mbstate_rec 1 "mom native born" 2 "mom foreign born"  3 "unknown"
label define mracerec 1 white 2 black 3 "amer ind or alaskan nat" 4 "asian or pac islndr"
label define mracehisp 1 mexican 2 "puerto rican" 3 cuban 4 "central and south amer" 5 "other and unknown hisp" 6 "non-hisp white" 7 "non-hisp black" 8 "non-hisp other races" 9 "origin unknown"
label define mar 1 yes 2 no 9 unknown 
label define meducA 1 "8th grd or less" 2 "9th-12 grd, no diploma" 3 "hs grad or ged" 4 "some college, no degree" 5 "assoc degree" 6 "bachelor's degree" 7 "master's degree" 8 "doctorate or professional degree" 9 "unknown"
label define umeduc 0 "no formal ed"  13 "1 yr of college" 14 "2 yrs of college" 15 "3 yrs of college" 16 "4 yrs of college" 17 "5 or more yrs of college" 99 unknown
label define meducS 1 "0-8 yrs" 2 "9-11 yrs" 3 "12 yrs" 4 "13-15 yrs" 5 "16 yrs and over" 6 "unknown"
label define lbo_rec 8 "8 or more live births" 9 unknown
label define tbo_rec 8 "8 or more total births" 9 unknown
label define ufagecomb 99 "unknown"
label define fracerec 1 white 2 black 3 "amer ind or alaskan nat" 4 "asian or pac islndr" 9 unknown
label define fracehisp 1 mexican 2 "puerto rican" 3 cuban 4 "central and south amer" 5 "other and unknown hisp" 6 "non-hisp white" 7 "non-hisp black" 8 "non-hisp other races" 9 "origin unknown"
label define feducA 1 "8th grd or less" 2 "9th-12 grd, no diploma" 3 "hs grad or ged" 4 "some college, no degree" 5 "assoc degree" 6 "bachelor's degree" 7 "master's degree" 8 "doctorate or professional degree" 9 "unknown"
label define dplural 1 single 2 twin 3 triplet 4 quadruplet 5 "quintuplet or higher"
label values dob_wk dob_wk
label values mager mager
label values mbstate_rec mbstate_rec
label values mracerec mracerec
label values mracehisp mracehisp
label values mar mar
label values meducA meducA
label values umeduc umeduc
label values meducS meducS
label values lbo_rec lbo_rec
label values tbo_rec tbo_rec
label values ufagecomb ufagecomb
label values fracerec fracerec
label values fracehisp fracehisp
label values feducA feducA
label values dplural dplural

drop if ostate == "AS" | ostate == "PR" | ostate == "VI" | ostate == "MP" | ostate == "GU"
desc, fullnames

#delimit ;
tab1 dob_yy dob_mm dob_wk ostate 
mager mbstate_rec mracerec mracehisp mar meducA umeduc meducS 
ufagecomb fracerec fracehisp feducA
lbo_rec tbo_rec dplural, mi;
#delimit cr

tab mracehisp mracerec, mi
tab meducA umeduc, mi
summ mager
tab meducA if version == "A", mi
tab meducS if version == "S", mi
tab1 meducA meducS, mi

tab  fagerpt, mi
tab  fagecomp, mi
tab  ufagecomp, mi
tab fagecomb, mi
tab  ufagecomb, mi

save NATL`y'US.AllCnty.basicdemography.dta, replace
}
log close

